package
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	public class Eye extends MovieClip
	{
		public static const LEFT:String = "left";
		public static const RIGHT:String = "right";
		public static const NONE:String = "none";
		//public var
		public var type:String;
		public var backColor:uint, irisColor:uint;
		public var WIDTH:Number, HEIGHT:Number;
		// private objects
		private var back:Sprite, toplid:Sprite, bottomlid:Sprite, ball:Sprite, iris:Sprite, pupil:Sprite, speck:Sprite;
		// private var
		
		
		public function Eye(WIDTH:Number, HEIGHT:Number, backColor:uint, type:String=NONE)
		{
			this.mouseEnabled = false;
			this.mouseChildren = false;
			
			this.backColor = backColor;
			this.irisColor = Math.ceil(0xAAAAAA * Math.random()) + 0x333333; 
			this.WIDTH = WIDTH;
			this.HEIGHT = HEIGHT;
			if (type == LEFT || type == RIGHT)
			{
				this.type = type;
			} else
			{
				this.type = NONE;
			}
			back = new Sprite(); 
			toplid = new Sprite(); 
			bottomlid = new Sprite();
			ball = new Sprite();
			iris = new Sprite();
			pupil = new Sprite();
			speck = new Sprite();
			
			//create order on eyes
			this.addChild(back);
			back.addChild(ball);
			ball.addChild(iris);
			iris.addChild(pupil);
			pupil.addChild(speck);
			ball.addChild(toplid);
			ball.addChild(bottomlid);
			
			drawEyeOpen();
		}
		
		/** Function draws eye fully open */
		public function drawEyeOpen()
		{
			// back of eye
			back.graphics.clear();
			back.graphics.beginFill(backColor);
			back.graphics.drawEllipse(-WIDTH/2, -HEIGHT/2, WIDTH, HEIGHT);
			back.graphics.endFill();
			// white of the eye
			ball.graphics.clear();
			ball.graphics.beginFill(0xFFFFFF);
			ball.graphics.drawEllipse(-WIDTH/2+2, -HEIGHT/2+2, WIDTH-4, HEIGHT-4);
			ball.graphics.endFill();
			// color of the eye
			iris.graphics.clear();
			iris.graphics.beginFill(0x000000);
			iris.graphics.drawEllipse(-WIDTH/4, -HEIGHT/4, WIDTH/2, HEIGHT/2);
			iris.graphics.endFill();
			// black of the eye
			pupil.graphics.clear();
			pupil.graphics.beginFill(0x000000);
			pupil.graphics.drawEllipse(-WIDTH/8, -HEIGHT/8, WIDTH/4, HEIGHT/4);
			pupil.graphics.endFill();
			// draw a speck on the pupil
			speck.graphics.clear();
			speck.graphics.lineStyle(2,0xFFFFFF);
			speck.graphics.moveTo(-2,0);
			speck.graphics.lineTo(2,0);
			speck.graphics.moveTo(0,-2);
			speck.graphics.lineTo(0,2);
		}
	}
}